package com.bird.pro.ctrl;

import java.util.List;

import org.apache.log4j.chainsaw.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bird.pro.pojo.BirdPosttype;
import com.bird.pro.service.IPostTypeService;
import com.bird.pro.vo.PostType;

@Controller
@RequestMapping("postType")
public class PostTypeController {

	@Autowired
	private IPostTypeService postTypeService;
	
	@RequestMapping("main")
	public String postTypeMain(Model model){
		return "type/main";
	}
	
	@RequestMapping("list")
	public String postTypeList(Model model){
		List<PostType> postTypes = postTypeService.getPostTypes();
		model.addAttribute("types", postTypes);
		return "type/list";
	}
	
	@RequestMapping("secondType")
	@ResponseBody
	public List<BirdPosttype> getSecondType(Integer id){
		List<BirdPosttype> posttypes = postTypeService.getSecondTypes(id);
		return posttypes;
	}
	
	@RequestMapping("save")
	@ResponseBody
	public String savePostType(BirdPosttype posttype){
		int success = postTypeService.saveType(posttype);
		if (success > 0) {
			return "success";
		}
		return "";
	}
	
	@RequestMapping("update")
	@ResponseBody
	public String updatePostType(BirdPosttype posttype){
		int success = postTypeService.updateType(posttype);
		if (success > 0) {
			return "success";
		}
		return "";
	}
	
	@RequestMapping("delete")
	@ResponseBody
	public String deletePostType(Integer id){
		int success = postTypeService.deleteType(id);
		if (success > 0) {
			return "success";
		}
		return "";
	}
}
